home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / hdiff122.zip / HDIFF.DOC < prev    next >
Encoding:
Text File  |  1988-01-07  |  24.7 KB  |  594 lines

  1.                                   hdiff 1.22
  2.  
  3.         Purpose
  4.         -------
  5.         Hdiff compares two DOS text files and records the differences
  6.         between them in a third file.  Although hdiff can be used for
  7.         simple "what's changed?" purposes, its real function is to
  8.         assist in maintaining program source code or similar text files
  9.         that change over time.  By maintaining a original, base file and
  10.         a series of "difference" files, it's possible to retain all
  11.         versions of a file at a great savings in space over retaining
  12.         the full text of all versions.
  13.  
  14.         The hdiff system includes an auxiliary program, hed, that is
  15.         used to apply the difference files to the original (although
  16.         EDLIN can also be used if the files are small enough).
  17.  
  18.  
  19.         New in version 1.22
  20.         -------------------
  21.         The following features have been changed or added since version
  22.         1.14, the last publicly released version:
  23.  
  24.         1. A new difference-applier (HED.EXE) is included.  This
  25.         replaces most use of EDLIN for the hdiff system and allows you
  26.         to apply multiple update files in one operation.
  27.  
  28.         2. The syntax of hdiff has changed slightly:
  29.             a. A third filename can be supplied on the command line.
  30.                This replaces the redirection used in earlier versions.
  31.             b. It is no longer necessary to specify a maximum number
  32.                of lines (the old -nnnn parameter).  For downward
  33.                compatibility, hdiff 1.22 will accept and ignore the
  34.                parameter if present.
  35.  
  36.         3. The true file date of the original file is retained if you
  37.         use hdiff and hed as described below.
  38.  
  39.         4. Maximum line length has been extended to 1000 characters.
  40.  
  41.  
  42.         Running hdiff
  43.         -------------
  44.         The general syntax for hdiff is:
  45.  
  46.             hdiff [-ecs] old-file new-file [dif-file]
  47.  
  48.         The simplest use of hdiff is exemplified by:
  49.  
  50.             hdiff oldfile.txt newfile.txt
  51.  
  52.         which displays a simple report of differences between the two
  53.         files: it shows which lines of OLDFILE.TXT do not appear in
  54.         NEWFILE.TXT (deletions), and which lines of NEWFILE.TXT do not
  55.         appear in OLDFILE.TXT (insertions).  The simple change report
  56.         consists of text lines in this format:
  57.  
  58.             nnnn[+/-] text
  59.  
  60.         A '+' format indicates that the line is new (an insertion); the
  61.         '-' indicates that the line is gone (a deletion).  Thus:
  62.  
  63.             0001- This line appears in the old file only
  64.             0001+ This line appears in the new file only
  65.  
  66.         The 'nnnn' represents the line number.  For '+' lines, it's the
  67.         line number in the new file; for '-' lines, it's the line number
  68.         in the old file.
  69.  
  70.         (Note that the first file named on the command line is always
  71.         assumed to be the "old" file, and the second is the "new" file.)
  72.  
  73.         If you want the report to be sent to a text file rather than to
  74.         the screen, simply include the file name as a third parameter:
  75.  
  76.             hdiff oldfile.txt newfile.txt changes.txt
  77.  
  78.         NOTE: the simple report does not show lines that have been
  79.         moved.  The edlin-format report (-e switch) does include moved
  80.         lines.  Use the -e report for maintaining difference files; the
  81.         simple report does not contain enough information.
  82.  
  83.  
  84.         Optional switches
  85.         -----------------
  86.         Here are the switches that can optionally be added to the
  87.         command line.  They must precede the file names:
  88.  
  89.         -c      Case insensitive: hdiff ignores differences in
  90.                 alphabetic case.  Thus, the two lines:
  91.  
  92.                         This is text
  93.                         THIS IS TEXT
  94.  
  95.                 are not reported as changed.
  96.  
  97.         -e      Edlin: produce an edlin-compatible difference file
  98.                 rather than the simple difference report described
  99.                 above.  This switch is also used to created hed-format
  100.                 files.  See succeeding sections for more information.
  101.  
  102.         -s      Space insensitive: hdiff ignores differences in spacing.
  103.                 This, the two lines:
  104.  
  105.                         This is text
  106.                         This  is    text
  107.  
  108.                 are not reported as changed.
  109.  
  110.         The switches may be combined, and they may be in any order:
  111.  
  112.                 -e -c
  113.                 -ec
  114.                 -ce
  115.                 -c -e
  116.  
  117.         are all equivalent.  All switches must, however, precede the
  118.         first filename.
  119.  
  120.         Examples of hdiff use:
  121.  
  122.             hdiff foo.c newfoo.c
  123.  
  124.                 compares file 'foo.c' with file 'newfoo.c' and displays
  125.                 a simple report showing insertions (lines in newfoo that
  126.                 do not appear in foo) and deletions (lines in foo that
  127.                 do not appear in newfoo).  Lines that have been moved
  128.                 but are otherwise unchanged do not appear in this
  129.                 report.
  130.  
  131.             hdiff -ec foo.c newfoo.c foo.114
  132.  
  133.                 compares foo.c with newfoo.c, ignoring case differences,
  134.                 and prepares an edlin/hed script in the file foo.114.
  135.                 This script, if applied to foo as described below, will
  136.                 create a copy of newfoo.
  137.  
  138.  
  139.         Applying difference files: edlin and version control
  140.         ----------------------------------------------------------
  141.         The main purpose of hdiff is to assist you in maintaining
  142.         multiple versions of program source or other text files.  Many
  143.         programmers like to keep archival copies of old source, for any
  144.         of a number of reasons (one reason: sometimes changes don't work
  145.         and it's necessary to go back to a previous version!).  You
  146.         could simply keep an archive or library with the complete text
  147.         of all versions, but this is wasteful of disk space.
  148.  
  149.         A better solution (short of purchasing a true SCCS ["Source Code
  150.         Control System"] for big bucks) is to use hdiff and hed or edlin
  151.         to keep one original source file plus smaller difference files
  152.         that can be used to re-create any version.
  153.  
  154.         To see how this works, assume that you have an old version of
  155.         your program MYPROG.C (in a file called MYPROG.SCC) and a new
  156.         version named MYPROG.C:
  157.  
  158.                 myprog.scc     (version 1.00)
  159.                 myprog.c       (version 1.10)
  160.  
  161.         To create a difference file, use hdiff:
  162.  
  163.             hdiff -e myprog.scc myprog.c myprog.110
  164.  
  165.         After hdiff is finished, you will have a file (MYPROG.110) that
  166.         contains the differences between 1.00 and 1.10.  Because of the
  167.         -e switch, this file is in a special format:  it is actually the
  168.         text of a series of edlin commands that would turn version 1.00
  169.         source into version 1.10 source.  It is an edlin script.  So, if
  170.         you were to execute the commands (remember that MYPROG.SCC is
  171.         version 1.00):
  172.  
  173.             copy myprog.scc myprog.c
  174.             edlin myprog.c < myprog.110
  175.  
  176.         the result (after edlin finished) would be a file called
  177.         MYPROG.C that contains the source for version 1.10.  Thus,
  178.         between the original (1.00) MYPROG.SCC and the difference file
  179.         MYPROG.110 you have all you need to re-create either version of
  180.         the program.  Chances are, however, that MYPROG.110 is much
  181.         smaller than the full source for MYPROG.C, so considerable
  182.         storage is saved.
  183.  
  184.         Note that edlin cannot deal, in this context, with files larger
  185.         than about 48K.  If you try to apply a difference file to a base
  186.         file larger than 48K using edlin, the resultant file will be
  187.         damaged and probably unusable.  For this reason and others, we
  188.         recommend using the supplied program "hed" rather than edlin.
  189.  
  190.  
  191.         Using hed
  192.         ---------
  193.         Hed is a simple program that can be used in place of edlin to
  194.         apply update files.  We prefer it to edlin for this purpose;
  195.         there are several reasons:
  196.  
  197.             1. It's much faster.
  198.             2. It doesn't suffer from Edlin's 48K file size restriction.
  199.             3. It handles file dates in a more useful manner.
  200.             4. It can create a new file with a different name.
  201.             5. It can apply more than one update file at a time.
  202.  
  203.         Hed's full syntax is:
  204.  
  205.             hed [-nv] base diff[+diff...] [new]
  206.  
  207.         where base is the original source file (MYPROG.SCC, in the above
  208.         example), diff is the difference file created by hdiff, and new
  209.         is the optional output file name.
  210.  
  211.         The optional parameters are:
  212.  
  213.             -n  No sort: instructs hed not to sort multiple update
  214.                 files, i.e., to apply them in the stated order.
  215.  
  216.             -n  reVerse: instructs hed to sort multiple updates
  217.                 files is reverse order (more about this shortly).
  218.  
  219.         If both -n and -v are specified, -n takes precedence.
  220.  
  221.         This command creates MYPROG version 1.10 from the 1.00 source
  222.         and the difference file created above:
  223.  
  224.             hed myprog.scc myprog.110 myprog.c
  225.  
  226.         On completion, you'll have the 1.10 source in the file MYPROG.C.
  227.  
  228.         If you do not include a third file name (new), hed will change
  229.         the extension of the base file to BAK and re-use the base file
  230.         name for the output.  In other words,
  231.  
  232.             hed myprog.scc myprog.110
  233.  
  234.         wil leave the original MYPROG.SCC in MYPROG.BAK, and the new
  235.         MYPROG.SCC will be the source for version 1.10.  This is exactly
  236.         what edlin would do.
  237.  
  238.         Note that you can apply several updates at once:
  239.  
  240.             hed myprog.scc myprog.110+myprog.111+myprog.120 myprog.c
  241.  
  242.         More information about this feature is in the section called
  243.         "Hed and Multiple Updates".
  244.  
  245.  
  246.         File dates
  247.         ----------
  248.         If you use hdiff's -e switch and specify an output file, hdiff
  249.         will set the difference file date to the same date as new-file.
  250.         That is, after
  251.  
  252.             hdiff -e myprog.scc myprog.c myprog.110
  253.  
  254.         MYRPOG.110 will have the same date as MYPROG.C.  This is useful
  255.         because hed uses the difference file date for its own output.
  256.         That is, after:
  257.  
  258.             hed myprog.scc myprog.110 myprog.c
  259.  
  260.         MYPROG.C will have the same date as MYPROG.110, which, in turn,
  261.         has the same date as the original copy of MYPROG.C.
  262.  
  263.         In this manner, the hdiff/hed system can retain true file dates
  264.         for all versions.
  265.  
  266.  
  267.         Cdelta and cget
  268.         ---------------
  269.         The two demonstration batches, cdelta and cget, provide a quick
  270.         sample of the kinds of things that can be done with hdiff and
  271.         hed.  The two batches are designed for C programs; to revise
  272.         them for other languages, simply replace all references to ".c"
  273.         with the desired extension (.asm, for example).
  274.  
  275.         The purpose of cdelta is to generate a change script that will
  276.         convert a "base" source file into a specified version of your
  277.         source.  Cget performs the inverse task; it applies a specified
  278.         change file to the base and produces a file containing the
  279.         specified version.  File naming conventions are as follows:
  280.  
  281.                 file.scc:    "base" source; scc = source code control
  282.                 file.###:    A change script to produce version ###
  283.                 file.c:      The current version (cdelta), or the
  284.                              output file (cget)
  285.  
  286.         For example, suppose you are working with a C program called
  287.         FOO.  A base (earliest) version of this file should be in
  288.         FOO.SCC.  You have just finished revision 1.10 of FOO.  To
  289.         create the change file, type
  290.  
  291.                 cdelta foo 110
  292.  
  293.         The batch will create a new file, FOO.110; this file is an
  294.         edlin/hed compatible script that will convert FOO.SCC into
  295.         version 1.10 of FOO.C.
  296.  
  297.         To retrieve a specified version, say 1.05, use
  298.  
  299.                 cget foo 105
  300.  
  301.         The batch will apply the script FOO.105 to FOO.SCC (using hed)
  302.         and produce FOO.C, which will contain the source for version
  303.         1.05.
  304.  
  305.         Note that cget always creates a file with a C extension,
  306.         overwriting any existing file with the same name.  This implies
  307.         that you do NOT keep your current source in FILE.C; you keep the
  308.         current source only by retaining FILE.SCC and the delta files.
  309.  
  310.  
  311.         Sequential version control
  312.         --------------------------
  313.         If you have access to a system that provides more sophisticated
  314.         control over the execution of DOS commands (Personal REXX or
  315.         Extended Batch Language, for example), it's not difficult to
  316.         provide for "sequential" version control for even greater space
  317.         savings.  The demo batch files, cdelta and cget, use only one
  318.         base file; each new version is represented by a difference file
  319.         that is the difference from the original version:
  320.  
  321.                 foo.scc + foo.110 = foo.c (version 1.10)
  322.                 foo.scc + foo.111 = foo.c (version 1.11)
  323.                 foo.scc + foo.120 = foo.c (version 1.20)
  324.  
  325.         This scheme has the virtue of simplicity, but there is a
  326.         disadvantage:  the difference files just keep getting bigger and
  327.         bigger.  Each difference file contains the cumulative
  328.         differences of all preceding versions.  You may eventually find
  329.         that the difference files are larger than the base file.
  330.  
  331.         The sequential method keeps differences between versions, rather
  332.         than differences between the current version and an original
  333.         base.  That is, FOO.110 is the difference between FOO.SCC and
  334.         version 1.10; FOO.111 is the difference between versions 1.10
  335.         and 1.11; FOO.120 is the difference between versions 1.11 and
  336.         1.20.  To obtain version 1.20, we start with the base file and
  337.         apply all difference files sequentially:
  338.  
  339.                 foo.scc + foo.110 = temp.c (foo version 1.10)
  340.                 temp.c + foo.111 = temp2.c (foo version 1.11)
  341.                 temp2.c + foo.120 = foo.c  (foo version 1.20)
  342.  
  343.         This scheme is obviously somewhat more complex, but it allows
  344.         you to save all versions of a file in the least amount of space.
  345.  
  346.         Note that the single command:
  347.  
  348.                 hed foo.scc foo.110+foo.111+foo.120 hed.c
  349.  
  350.         would do the whole job in one step.  See the next section for
  351.         more information on how to apply sequential update files.
  352.  
  353.  
  354.         Hed and Multiple Updates
  355.         ------------------------
  356.         As noted, you can apply more than one update file per hed run by
  357.         using the "+" operator:
  358.  
  359.             hed file.scc file.110+file.111+file.112 file.c
  360.  
  361.         Here are the full rules:
  362.  
  363.             1. You can use wildcard file specifications.  For example,
  364.                if FILE.110, FILE.111, and FILE.112 were the only update
  365.                files in the current directory, you could use:
  366.  
  367.                     hed file.scc file.1* file.c
  368.  
  369.                If you had FILE.110, FILE.121, and FILE.200:
  370.  
  371.                     hed file.scc file.1*+file.2* file.c
  372.  
  373.             2. The file list must be separated by "+" ONLY; spaces are
  374.                not permitted.  Thus,
  375.  
  376.                     hed file.scc file.100 + file.110
  377.  
  378.                 is not legal.  It must be
  379.  
  380.                     hed file.scc file.100+file.110
  381.  
  382.             3. A total of up to 40 update files (including all
  383.                wildcard expansions) may be specified.
  384.  
  385.             4. Hed sorts the files by extension and applies them in
  386.                sorted order, one after the other.  (If you use the -v
  387.                switch, hed will sort in reverse order; if you use -n, no
  388.                sorting will be performed.)  In other words, if you
  389.                enter:
  390.  
  391.                     hed file.scc file.1* file.c
  392.  
  393.                and files FILE.120 and FILE.110 are present in the
  394.                current directory (in that order), hed will:
  395.  
  396.                     a. Sort the update files by extension; 110 will
  397.                        precede 120 even though they are "out of order"
  398.                        in the disk directory.
  399.                     b. Read in FILE.SCC.
  400.                     c. Apply FILE.110 updates, creating an "in-memory"
  401.                        copy of version 110.
  402.                     d. Apply FILE.120 updates, creating an "in-memory"
  403.                        copy of version 120.
  404.                     e. Write out the resultant file as FILE.C
  405.  
  406.         Note that intermediate versions are not written to disk.
  407.  
  408.  
  409.         Reverse sorting
  410.         ---------------
  411.         The purpose of the -v switch is to allow you to implement a
  412.         "reverse" version scheme.  Rather than keeping an original base
  413.         and multiple updates from that base, some people prefer to keep
  414.         the full current source and difference files for earlier
  415.         versions.  For example, if you have FOO versions 1.00, 1.05, and
  416.         1.10 (the current), the "traditional" scheme would be to keep
  417.         the source for 1.00 and update files for 1.05 and 1.10:
  418.  
  419.                 foo.scc + foo.105 -> foo.c (version 1.05)
  420.                 foo.c + foo.110 ->   foo.c (version 1.10)
  421.  
  422.         The "reverse" scheme would be to keep the full source to version
  423.         1.10 and keep a difference file that would create 1.05 and 1.00:
  424.  
  425.                 foo.scc = current (1.10)
  426.                 foo.scc + foo.105 -> foo.c (version 1.05)
  427.                 foo.c + foo.100 ->   foo.c (version 1.00)
  428.  
  429.         Using this scheme, the hed command
  430.  
  431.                 hed foo.scc foo.1* foo.c
  432.  
  433.         (to create version 1.00) wouldn't work, because the update files
  434.         would be sorted in the wrong order:  1.00 would precede and be
  435.         applied before 1.05.  However, the command
  436.  
  437.                 hed -v foo.scc foo.1* foo.c
  438.  
  439.         would sort in reverse order and apply 1.05 before 1.00,
  440.         correctly producing 1.00.
  441.  
  442.         The advantage to the "reverse" scheme is that the most current
  443.         version of the source can be obtained immediately, without the
  444.         need to apply many sequential files.
  445.  
  446.  
  447.         Other uses of hdiff
  448.         -------------------
  449.         In addition to the version control application of hdiff, you can
  450.         find other uses for the system.
  451.  
  452.         The simplest use for hdiff is to compare two files to see if
  453.         they are the same.  This can be used to check for corruption
  454.         during backups, copies, etc., or to determine which of two files
  455.         is newer.  Even this simple use of hdiff can be useful in
  456.         unexpected ways, however.  For example, look at this small batch
  457.         file:
  458.  
  459.                 dir a: > temp
  460.                 find "-" temp > dir.a
  461.                 dir b: > temp
  462.                 find "-" temp > dir.b
  463.                 hdiff dir.b dir.a > temp.bat
  464.                 erase dir.a
  465.                 erase dir.b
  466.                 erase temp
  467.  
  468.         This batch can be used for a simple backup system.  Assume that
  469.         the default directory in drive A contains a series of files that
  470.         you want to backup, and that the default directory in drive B
  471.         contains the same set of files from the last backup.  The batch
  472.         will isolate differences between the two directories and prepare
  473.         a file called TEMP.BAT that contains a list of those files that
  474.         have been changed or added since the last backup.  Many popular
  475.         text editors could very easily convert (or be programmed to
  476.         automatically convert) TEMP.BAT file into a series of copy
  477.         commands that could be used, in batch mode, to perform the
  478.         copying.
  479.  
  480.  
  481.         Restrictions
  482.         ------------
  483.         The following act, in one way or another, as restrictions on
  484.         hdiff:
  485.  
  486.         - File format:  hdiff is intended as a DOS text file differencer
  487.         only.  It is NOT a replacement for the DOS utility COMP or our
  488.         own QCMP.  Don't use it on binary (program or data) files, or on
  489.         most word processor files.
  490.  
  491.         - Available memory:  hdiff works entirely in memory, and it
  492.         needs quite a lot.  The starting memory requirement is about
  493.         220K; then, for each UNIQUE line in either file, hdiff needs
  494.         about 12 bytes plus the length of the line.  Identical lines are
  495.         stored only once, no matter how many times they occur.  Thus,
  496.         the two files:
  497.  
  498.             File 1:
  499.                 Line 1
  500.                 /* Comment */
  501.                 Line 2
  502.  
  503.             File 2:
  504.                 Line 1
  505.                 /* Comment */
  506.                 /* Comment */
  507.                 Line 2
  508.                 Line 3
  509.  
  510.         have four unique lines ("Line 1", "/* Comment */", "Line 2", and
  511.         "Line 3").  These will use about 79 bytes of storage (in
  512.         addition to the 220K starting memory!):
  513.  
  514.             4 lines @ 12 bytes:  48
  515.             Total text length:   31
  516.  
  517.         - Number of lines: neither file can exceed 5000 lines of text.
  518.  
  519.         - Line size: limited to a maximum of 1000 characters per line.
  520.  
  521.  
  522.         Notes on the algorithm
  523.         ----------------------
  524.         Hdiff uses a file comparison algorithm that was developed by
  525.         Paul Heckel and described by Dave Cortesi in Dr.  Dobb's Journal
  526.         #94 (August, 1984).  The algorithm is substantially more
  527.         efficient than traditional file comparison methods; it can
  528.         generate a difference report between two files in little more
  529.         than the time it takes for the program to read them.
  530.  
  531.         Hdiff was derived from Cortesi's demonstration program, with
  532.         substantial modifications that
  533.  
  534.             - accomodate differences between edlin and CP/M's "ed" (for
  535.               which the demo was written)
  536.  
  537.             - allow use of edlin's block move capabilities
  538.  
  539.             - allow for much larger files through the use of all
  540.               available memory.
  541.  
  542.             - allow case and spacing insensitive comparisons.
  543.  
  544.             - allow the user to request the simpler difference report
  545.               rather than the edlin script.
  546.  
  547.  
  548.         Copyright/License/Warranty
  549.         --------------------------
  550.         This document and the program files HDIFF.EXE and HED.EXE ("the
  551.         software") are copyrighted by the author.  The copyright owner
  552.         hereby licenses you to:  use the software; make as many copies
  553.         of the program and documentation as you wish; give such copies
  554.         to anyone; and distribute the software and documentation via
  555.         electronic means.  There is no charge for any of the above.
  556.  
  557.         However, you are specifically prohibited from charging, or
  558.         requesting donations, for any such copies, however made; and
  559.         from distributing the software and/or documentation with
  560.         commercial products without prior permission.  An exception is
  561.         granted to not-for-profit user's groups, which are authorized to
  562.         charge a small fee (not to exceed $7) for materials, handling,
  563.         postage, and general overhead.  NO FOR-PROFIT ORGANIZATION IS
  564.         AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
  565.         THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
  566.         SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
  567.  
  568.         THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
  569.         ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
  570.         OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
  571.         ANY OTHER SUCH FEE FOR THE DISTRIBUTION.  NO FOR-PROFIT
  572.         ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
  573.         FOR WHICH MONEY IS CHARGED.  PERIOD.
  574.  
  575.         No copy of the software may be distributed or given away without
  576.         this document; and this notice must not be removed.
  577.  
  578.         There is no warranty of any kind, and the copyright owner is not
  579.         liable for damages of any kind.  By using this free software,
  580.         you agree to this.
  581.  
  582.         The software and documentation are:
  583.  
  584.                        Copyright (C) 1985, 1986, 1987 by
  585.                             The Cove Software Group
  586.                             Christopher J. Dunford
  587.                                  P.O. Box 1072
  588.                            Columbia, Maryland 21044
  589.  
  590.                                 (301) 992-9371
  591.                         CompuServe 76703,2002 [IBMNET]
  592.  
  593.         Software and documentation author: Chris Dunford
  594.